package com.jiantu.controller;

import com.jiantu.common.PageBean;
import com.jiantu.common.R;
import com.jiantu.domain.dto.PageDTO;
import com.jiantu.domain.pojo.Classes;
import com.jiantu.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *班级管理
 */
@RestController
@RequestMapping("/classes")
@CrossOrigin
public class ClassesController {
    @Autowired
    private ClassesService classesService;

    @GetMapping("/{id}")
    public Classes findById( @PathVariable("id") Integer id) {
        return classesService.findById(id);
    }

    @GetMapping("/getClassesListByPage")
    public R getClassesListByPage(PageDTO pageDTO ) {
        PageBean classesList = classesService.findByPage(pageDTO);
        return R.success(classesList);
    }

    @PostMapping("/addClasses")
    public R insert(@RequestBody Classes classes) {

        int insert = classesService.insert(classes);
        if (insert >=1 ){
            return R.success();
        }
        return R.error("添加失败");

    }

    @PostMapping("/updateClasses")
    public R update(@RequestBody Classes classes) {

        int update = classesService.update(classes);
        if (update >=1 ){
            return R.success();
        }
        return R.error("更新失败");
    }

    @DeleteMapping("/delClasses/{id}")
    public R deleteById( @PathVariable("id") Integer id) {

        int del = classesService.deleteById(id);
        if (del >=1 ){
            return R.success();
        }
        return R.error("删除失败");
    }
}
